# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=httplib2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.14.0
pkgrel=1
pkgdesc="Comprehensive HTTP client library, supporting many features (mingw-w64)"
arch=('any')
license=('MIT')
url="https://github.com/httplib2/httplib2"
depends=("${MINGW_PACKAGE_PREFIX}-ca-certificates")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/httplib2/httplib2/archive/v${pkgver}.tar.gz
        cert.patch)
sha256sums=('4b0a937532597b681917a88e47eaf6aba00d5c209e1b6524cb0779d08856d79f'
            '3503625ade773c17c9c44f4017aec634ff03db0073eb3ec11e6882a466d7aae6')

prepare() {
  pushd "${_realname}-${pkgver}"

  # Patch, ref FS#40179
  patch -p1 -i "${srcdir}/cert.patch"

  popd

  # Prepare one build directory for each package
  cp -a "${_realname}-${pkgver}" build-python2
  cp -a "${_realname}-${pkgver}" build-python3
}

build() {
  echo "Empty"
}

package_python2-httplib2() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-certifi"
           "${MINGW_PACKAGE_PREFIX}-ca-certificates")

  cd "${srcdir}/build-python2"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1

  #install -Dm644 LICENSE \
  #  "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE
}

package_python3-httplib2() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-certifi"
           "${MINGW_PACKAGE_PREFIX}-ca-certificates")

  cd "${srcdir}/build-python3"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1

  #install -Dm644 LICENSE \
  #  "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-httplib2() {
  package_python2-httplib2
}

package_mingw-w64-i686-python3-httplib2() {
  package_python3-httplib2
}

package_mingw-w64-x86_64-python2-httplib2() {
  package_python2-httplib2
}

package_mingw-w64-x86_64-python3-httplib2() {
  package_python3-httplib2
}
